package br.unicamp.ic.lsd;

import javax.jws.WebService;

import br.unicamp.ic.lsd.exceptions.EException;
import br.unicamp.ic.lsd.exceptions.FException;
import br.unicamp.ic.lsd.exceptions.IException;

@WebService(endpointInterface = "br.unicamp.ic.lsd.ServiceTwo", serviceName = "webserviceTwo")
public class ServiceTwoImpl implements ServiceTwo {
    private static boolean IExceptionThrow = false;
    private static boolean EExceptionThrow = false;
    private static boolean FExceptionThrow = false;
    private static long timeoutMethodOne = 0;
    private static long timeoutMethodTwo = 0;
    private static long timeoutMethodThree = 0;
    
    @Override
    public String methodOneWSTwo(int k) throws IException {
	if(IExceptionThrow)
	    k=1;
	
	try {
	    Thread.sleep(timeoutMethodOne);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
	
	switch (k) {
	case 0:
	    return "methodOneWSTwo executado com sucesso";
	case 1:
	    throw new IException("Falha do metodo methodOneWSTwo");
	}
	return "Algum erro ocorreu no metodo methodOneWSTwo";
    }
    
    @Override
    public String methodTwoWSTwo(int k) throws EException {
	if(EExceptionThrow)
	    k=1;
	
	try {
	    Thread.sleep(timeoutMethodTwo);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
	
	switch (k) {
	case 0:
	    return "methodTwoWSTwo executado com sucesso";
	case 1:
	    throw new EException("Falha do metodo methodTwoWSTwo");
	}
	return "Algum erro ocorreu no metodo methodTwoWSTwo";
    }
    
    @Override
    public String methodThreeWSTwo(int k) throws FException {
	if(FExceptionThrow)
	    k=1;
	
	try {
	    Thread.sleep(timeoutMethodThree);
	} catch (InterruptedException e) {
	    e.printStackTrace();
	}
	
	switch (k) {
	case 0:
	    return "methodThreeWSTwo executado com sucesso";
	case 1:
	    throw new FException("Falha do metodo methodThreeWSTwo");
	}
	return "Algum erro ocorreu no metodo methodThreeWSTwo";
    }
    
    @Override
    public boolean isIExceptionThrow() {
        return IExceptionThrow;
    }

    @Override
    public void setIExceptionThrow(boolean iExceptionThrow) {
        IExceptionThrow = iExceptionThrow;
    }

    @Override
    public boolean isEExceptionThrow() {
        return EExceptionThrow;
    }

    @Override
    public void setEExceptionThrow(boolean eExceptionThrow) {
        EExceptionThrow = eExceptionThrow;
    }

    @Override
    public boolean isFExceptionThrow() {
        return FExceptionThrow;
    }

    @Override
    public void setFExceptionThrow(boolean fExceptionThrow) {
        FExceptionThrow = fExceptionThrow;
    }

    @Override
    public long getTimeoutMethodOne() {
        return timeoutMethodOne;
    }

    @Override
    public void setTimeoutMethodOne(long timeoutMethodOne) {
        ServiceTwoImpl.timeoutMethodOne = timeoutMethodOne;
    }

    @Override
    public long getTimeoutMethodTwo() {
        return timeoutMethodTwo;
    }

    @Override
    public void setTimeoutMethodTwo(long timeoutMethodTwo) {
        ServiceTwoImpl.timeoutMethodTwo = timeoutMethodTwo;
    }

    @Override
    public long getTimeoutMethodThree() {
        return timeoutMethodThree;
    }

    @Override
    public void setTimeoutMethodThree(long timeoutMethodThree) {
        ServiceTwoImpl.timeoutMethodThree = timeoutMethodThree;
    }
    
}
